#pragma once
#include <nice2d/widgets/control.h>

class LayoutStyle : public ControlStyle
{
    DECLARE_OBJECT(LayoutStyle)
public:
    LayoutStyle();
    virtual ~LayoutStyle();
};

class LayoutInfo
{
public:
    virtual ~LayoutInfo()
    {
    }
};

enum LayoutResizeRule
{
    LayoutResizeRule_ResizeLayout = 0,
    LayoutResizeRule_ResizeControls
};

class Layout : public Control
{
    DECLARE_OBJECT(Layout)
public:
    Layout();
    virtual ~Layout();
public:
    void setMargin(float margin);
    float getMargin()const;

    void setSpacing(float spacing);
    float getSpacing()const;

    void setLayoutResizeRule(LayoutResizeRule rule);
    LayoutResizeRule getLayoutResizeRule()const;
public:
    uint32_t getWidgetCount()const;
    std::pair<ControlPointer,std::shared_ptr<LayoutInfo>> getWidgetByIndex(uint32_t index);

    bool containsControl(ControlPointer control);
public:
    virtual void addWidget(ControlPointer widget,std::shared_ptr<LayoutInfo> info);

    virtual ControlPointer getControlBelow(const sf::Vector2i &point)override;
    virtual bool doesHierarchyContain(ControlPointer other)const override;
protected:
    void onMouseExit() override;

    virtual void onPositionChanged() override;
    virtual void onSizeChanged() override;

    virtual void onUpdateControl(float deltaTime) override;
    virtual void adjust() = 0;
private:
    std::unique_ptr<class LayoutData> data;
};
